﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GUI.ThemMoi
{
    public partial class SachGUI : UserControl, GUI.UctrlGUI
    {
        BLL.ThemSachBLL _ThemSachBLL;

        public SachGUI()
        {
            InitializeComponent();
            _ThemSachBLL = new BLL.ThemSachBLL();
        }

        private void ResetGui()
        {
            txt_LuongTon.Text = 0.ToString();
            txt_TacGia.Text = String.Empty;
            txt_TenSach.Text = String.Empty;
            txt_TheLoai.Text = String.Empty;
        }

        public String getName()
        {
            return "THÊM MỚI SÁCH";
        }

        private void btn_ThemMoi_Click(object sender, EventArgs e)
        {
            if (txt_TenSach.Text == String.Empty)
            {
                MessageBox.Show("Tên Sách NULL");
                return;
            }

            if (txt_TacGia.Text == String.Empty)
            {
                MessageBox.Show("Tác Giả NULL");
                return;
            }

            if (txt_TheLoai.Text == String.Empty)
            {
                MessageBox.Show("Thể Loại NULL");
                return;
            }

            DTO.DauSachDTO dto = new DTO.DauSachDTO();
            dto.Ten = txt_TenSach.Text;
            dto.TacGia = txt_TacGia.Text;
            dto.TheLoai = txt_TheLoai.Text;
            if (txt_LuongTon.Text != String.Empty)
                dto.LuongTon = int.Parse(txt_LuongTon.Text.ToString());

            _ThemSachBLL.ThemMoi(dto);
            ResetGui();
        }

        private void SachGUI_Load(object sender, EventArgs e)
        {
            ResetGui();
        }

        private void btn_LamLai_Click(object sender, EventArgs e)
        {
            ResetGui();
        }

        private void txt_LuongTon_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) &&
                !char.IsDigit(e.KeyChar))
                e.Handled = true;
        }
    }
}
